package wnxy.wn44.shopwn.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wnxy.wn44.shopwn.entity.Perm;
import wnxy.wn44.shopwn.mapper.PermMapper;
import wnxy.wn44.shopwn.service.PermService;

import java.util.List;

@Service
public class PermServiceImpl implements PermService {
    private PermMapper permMapper;

    @Autowired
    public void setPermMapper(PermMapper permMapper) {
        this.permMapper = permMapper;
    }

    @Override
    public boolean savePerm(Perm perm) {
        return permMapper.insert(perm)!=0;
    }

    @Override
    public boolean deleteById(Integer permId) {
        return permMapper.deleteByPrimaryKey(permId)!=0;
    }

    @Override
    public Perm findById(Integer id) {
        return permMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Perm> findByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Perm> list=permMapper.selectAll();
        PageInfo<Perm> permPageInfo = new PageInfo<>(list);
        return permPageInfo;
    }

    @Override
    public boolean updatePerm(Perm perm) {
        return permMapper.updateByPrimaryKeySelective(perm)!=0;
    }
}
